import { defineStore } from 'pinia'
export const useMenuStore = defineStore('menu', {
  state: () => ({
    menus: [
      {
        type: 'slider',
        name: '聊天机器人',
        icon: 'Comment',
        index: '/home/index',
        active: true,
        children: []
      },
      {
        type: 'slider',
        name: '图片生成',
        icon: 'PictureFilled',
        index: '/home/img',
        active: true,
        children: []
      },
      {
        type: 'slider',
        name: 'Ai模型库',
        icon: 'Opportunity',
        index: '/home/modelImg',
        active: true,
        children: []
      },
      // {
      //   type: 'slider',
      //   name: '素材库',
      //   icon: 'Briefcase',
      //   index: '/home/statics',
      //   active: true,
      //   children: []
      // },
      {
        type: 'slider',
        name: 'vip办理',
        icon: 'InfoFilled',
        index: '/home/vip',
        active: true,
        children: []
      },
      // {
      //   type: 'slider',
      //   name: 'api调用链接',
      //   icon: 'share',
      //   index: '/home/api',
      //   active: true,
      //   children: []
      // },
      // {
      //   type: 'slider',
      //   name: 'ai网站模板下载',
      //   icon: 'share',
      //   index: '/home/module',
      //   active: true,
      //   children: []
      // },
      // {
      //   type: 'slider',
      //   name: 'chatgpt账号',
      //   icon: 'share',
      //   index: '/home/zhanghao',
      //   active: true,
      //   children: []
      // },

      {
        type: 'slider',
        name: '用户列表',
        icon: 'InfoFilled',
        index: '/home/user',
        active: true,
        children: []
      },
      {
        type: 'slider',
        name: '上传Ai图片',
        icon: 'InfoFilled',
        index: '/home/aiImg',
        active: true,
        children: []
      },
      // {
      //   type: 'slider',
      //   name: '分享即得现金',
      //   icon: 'StarFilled',
      //   index: '/home/yongjin',
      //   active: true,
      //   children: []
      // },
      {
        type: 'slider',
        name: '历史记录',
        icon: 'DeleteFilled',
        index: '/home/history',
        active: true,
        children: []
      }
      // {
      //   type: 'slider',
      //   name: '加群记住网站',
      //   icon: 'CirclePlusFilled',
      //   index: '/home/contact',
      //   active: true,
      //   children: []
      // }
    ],
    tabs: [],
    expandFold: false
  }),

  actions: {
    async expandFoldAct(data) {
      this.expandFold = !this.expandFold
    },
    async changeTabs(data) {
      let tabs = JSON.parse(JSON.stringify(this.tabs))

      let findTas = tabs.filter((v) => v.name == data.name && v.index == data.index)

      // 是否已存在
      if (findTas.length) {
        tabs.forEach((v, i, arr) => {
          if (v.name == data.name && v.index == data.index) {
            v.active = true
          } else {
            v.active = false
          }
        })
      } else {
        // 不能超过10个
        if (tabs.length > 10) {
          tabs = tabs.slice(1)
        }

        // 所有置为未选中
        tabs = tabs.map((v) => {
          return {
            ...v,
            active: false
          }
        })

        // 当前的激活菜单
        tabs.push({
          type: 'slider',
          name: data.name,
          icon: 'Document',
          index: data.index,
          active: true,
          children: []
        })
      }

      this.tabs = tabs
    },
    async setTabs(data) {
      this.tabs = data
    }
  }
})
